﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OpGen.Compiler.Analyser.UI
{
    internal class ElementTreeViewItem : TreeNode
    {
        public ElementTreeViewItem(Element Element)
        {
            var IImage = 0;
            this.Element = Element;

            if (Element is ProjectElement)
                Text = string.Format("Project ({0})", ((ProjectElement)Element).Projectname);
            else if (Element is FieldElement)
            {
                if (Element.Type.Type == Types.REFERENCE)
                    Text = string.Format("{0} : {1}", Element.Type.ReferenceName, Element.Elementname);
                else
                    Text = string.Format("{0} : {1}", Element.Type.Type.ToString(), Element.Elementname);
            }
            else if (Element is EnumItemElement)
                Text = string.Format("{0} = {1}", ((EnumItemElement)Element).Elementname, ((EnumItemElement)Element).Value);
            else
                Text = Element.Elementname;


            switch (Element.ElementType)
            {
                case ElementTypes.Namespace:
                    IImage = 1;
                    break;

                case ElementTypes.Class:
                    IImage = 4;
                    break;

                case ElementTypes.Message:
                    IImage = 8;
                    break;

                case ElementTypes.Enum:
                    IImage = 12;
                    break;

                case ElementTypes.EnumItem:
                    IImage = 3;
                    break;

                case ElementTypes.Field:
                    IImage = 16;
                    break;

                case ElementTypes.ListField:
                    IImage = 16;
                    break;

                case ElementTypes.Project:
                    IImage = 0;
                    break;

                default:
                    break;
            }

            if (IImage > 3)
            {
                switch (Element.Modifier)
                {
                    case Modifiers.None:
                        IImage += 0;
                        break;

                    case Modifiers.Unkown:
                        IImage += 0;
                        break;

                    case Modifiers.Private:
                        IImage += 2;
                        break;

                    case Modifiers.Public:
                        IImage += 0;
                        break;

                    case Modifiers.Internal:
                        IImage += 1;
                        break;

                    case Modifiers.Protected:
                        IImage += 3;
                        break;

                    default:
                        IImage += 0;
                        break;
                }
            }

            ImageIndex = IImage;
            SelectedImageIndex = IImage;
        }

        public Element Element { get; set; }
    }
}
